
#include <bits/stdc++.h>
using namespace std;

const int N = 3e5 + 5;
int n, pre[N], suc[N], a[N];
bool vis[N];

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    
    for(int i = 1; i <= n; i++){
        pre[i] = pre[i-1];
        if(!vis[a[i]]) pre[i]++;
        vis[a[i]] = true;
    }
    
    memset(vis, false, sizeof(vis));
    for(int i = n; i; i--){
        suc[i] = suc[i + 1];
        if(!vis[a[i]]) suc[i]++;
        vis[a[i]] = true;
    }
    
    int ans = 0;
    for(int i = 1; i < n; i++){
        ans = max(ans, pre[i] + suc[i + 1]);
    }
    
    printf("%d\n", ans);
    return 0;
}